home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 1VQZOU6 (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  5.7 KB  |  176 lines

  1. package com.sun.java.swing;
  2.  
  3. import com.sun.java.accessibility.Accessible;
  4. import com.sun.java.accessibility.AccessibleContext;
  5. import java.awt.Component;
  6. import java.awt.Container;
  7. import java.awt.IllegalComponentStateException;
  8. import java.awt.LayoutManager;
  9.  
  10. public class JRootPane extends JComponent implements Accessible {
  11.    protected JMenuBar menuBar;
  12.    protected Container contentPane;
  13.    protected JLayeredPane layeredPane;
  14.    protected Component glassPane;
  15.    protected JButton defaultButton;
  16.    protected DefaultAction defaultPressAction;
  17.    protected DefaultAction defaultReleaseAction;
  18.  
  19.    public JRootPane() {
  20.       this.setGlassPane(this.createGlassPane());
  21.       this.setLayeredPane(this.createLayeredPane());
  22.       this.setContentPane(this.createContentPane());
  23.       ((Container)this).setLayout(this.createRootLayout());
  24.       ((JComponent)this).setDoubleBuffered(true);
  25.       ((Component)this).setBackground(UIManager.getColor("control"));
  26.    }
  27.  
  28.    protected void addImpl(Component comp, Object constraints, int index) {
  29.       super.addImpl(comp, constraints, index);
  30.       if (this.glassPane != null && this.glassPane.getParent() == this && ((Container)this).getComponent(0) != this.glassPane) {
  31.          ((Container)this).add(this.glassPane, 0);
  32.       }
  33.  
  34.    }
  35.  
  36.    protected Container createContentPane() {
  37.       JComponent c = new JPanel();
  38.       ((Component)c).setName(((Component)this).getName() + ".contentPane");
  39.       ((Container)c).setLayout(new 1());
  40.       return c;
  41.    }
  42.  
  43.    protected Component createGlassPane() {
  44.       JComponent c = new JPanel();
  45.       ((Component)c).setName(((Component)this).getName() + ".glassPane");
  46.       c.setVisible(false);
  47.       ((JPanel)c).setOpaque(false);
  48.       return c;
  49.    }
  50.  
  51.    protected JLayeredPane createLayeredPane() {
  52.       JLayeredPane p = new JLayeredPane();
  53.       ((Component)p).setName(((Component)this).getName() + ".layeredPane");
  54.       return p;
  55.    }
  56.  
  57.    protected LayoutManager createRootLayout() {
  58.       return new RootLayout(this);
  59.    }
  60.  
  61.    public AccessibleContext getAccessibleContext() {
  62.       if (super.accessibleContext == null) {
  63.          super.accessibleContext = new AccessibleJRootPane(this);
  64.       }
  65.  
  66.       return super.accessibleContext;
  67.    }
  68.  
  69.    public Container getContentPane() {
  70.       return this.contentPane;
  71.    }
  72.  
  73.    public JButton getDefaultButton() {
  74.       return this.defaultButton;
  75.    }
  76.  
  77.    public Component getGlassPane() {
  78.       return this.glassPane;
  79.    }
  80.  
  81.    public JLayeredPane getLayeredPane() {
  82.       return this.layeredPane;
  83.    }
  84.  
  85.    public JMenuBar getMenuBar() {
  86.       return this.menuBar;
  87.    }
  88.  
  89.    public boolean isValidateRoot() {
  90.       return true;
  91.    }
  92.  
  93.    public void setContentPane(Container content) {
  94.       if (content == null) {
  95.          throw new IllegalComponentStateException("contentPane cannot be set to null.");
  96.       } else {
  97.          if (this.contentPane != null && this.contentPane.getParent() == this.layeredPane) {
  98.             this.layeredPane.remove(this.contentPane);
  99.          }
  100.  
  101.          this.contentPane = content;
  102.          this.layeredPane.add(this.contentPane, JLayeredPane.FRAME_CONTENT_LAYER);
  103.       }
  104.    }
  105.  
  106.    public void setDefaultButton(JButton defaultButton) {
  107.       JButton oldDefault = this.defaultButton;
  108.       this.defaultButton = defaultButton;
  109.       if (this.defaultPressAction == null) {
  110.          this.defaultPressAction = new DefaultAction(this, true);
  111.          this.defaultReleaseAction = new DefaultAction(this, false);
  112.          ((JComponent)this).registerKeyboardAction(this.defaultPressAction, KeyStroke.getKeyStroke(10, 0, false), 2);
  113.          ((JComponent)this).registerKeyboardAction(this.defaultReleaseAction, KeyStroke.getKeyStroke(10, 0, true), 2);
  114.       }
  115.  
  116.       if (oldDefault != defaultButton) {
  117.          this.defaultPressAction.setOwner(defaultButton);
  118.          this.defaultReleaseAction.setOwner(defaultButton);
  119.          if (oldDefault != null) {
  120.             ((Component)oldDefault).repaint();
  121.          }
  122.  
  123.          if (defaultButton != null) {
  124.             ((Component)defaultButton).repaint();
  125.          }
  126.       }
  127.  
  128.       ((JComponent)this).firePropertyChange("defaultButton", oldDefault, defaultButton);
  129.    }
  130.  
  131.    public void setGlassPane(Component glass) {
  132.       if (glass == null) {
  133.          throw new NullPointerException("glassPane cannot be set to null.");
  134.       } else {
  135.          boolean visible = false;
  136.          if (this.glassPane != null && this.glassPane.getParent() == this) {
  137.             ((Container)this).remove(this.glassPane);
  138.             visible = this.glassPane.isVisible();
  139.          }
  140.  
  141.          glass.setVisible(visible);
  142.          this.glassPane = glass;
  143.          ((Container)this).add(this.glassPane, 0);
  144.          if (visible) {
  145.             ((Component)this).repaint();
  146.          }
  147.  
  148.       }
  149.    }
  150.  
  151.    public void setLayeredPane(JLayeredPane layered) {
  152.       if (layered == null) {
  153.          throw new IllegalComponentStateException("layeredPane cannot be set to null.");
  154.       } else {
  155.          if (this.layeredPane != null && this.layeredPane.getParent() == this) {
  156.             ((Container)this).remove(this.layeredPane);
  157.          }
  158.  
  159.          this.layeredPane = layered;
  160.          ((Container)this).add(this.layeredPane, -1);
  161.       }
  162.    }
  163.  
  164.    public void setMenuBar(JMenuBar menu) {
  165.       if (this.menuBar != null && this.menuBar.getParent() == this.layeredPane) {
  166.          this.layeredPane.remove(this.menuBar);
  167.       }
  168.  
  169.       this.menuBar = menu;
  170.       if (this.menuBar != null) {
  171.          this.layeredPane.add(this.menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
  172.       }
  173.  
  174.    }
  175. }
  176.